package cn.yuan.xiaoyu.wangmodule.bean;

import net.sourceforge.pinyin4j.PinyinHelper;

/**
 * Created by yukuoyuan on 2017/3/2.
 */

public class ContactsBean {
    private String name;
    private String avatar;
    private String pinyin;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
        this.pinyin = getHeadChar(name);
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getPinyin() {
        return pinyin;
    }

    public void setPinyin(String pinyin) {
        this.pinyin = pinyin;
    }

    /**
     * 得到首字母
     *
     * @param str
     * @return
     */
    public String getHeadChar(String str) {
        String convert = "";
        char word = str.charAt(0);
        String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word);
        if (pinyinArray != null) {
            convert += pinyinArray[0].charAt(0);
        } else {
            convert += word;
        }
        return convert.toUpperCase();
    }
}
